﻿using System;
using System.Collections.Generic;
using Db4objects.Db4o.Linq;
using Froggy.Data.Db4o;
using System.Collections;

namespace Froggy.Stocks
{
    public class Stock
    {
        private string _Symbol;
        private string _CompanyName;

        public string Symbol
        {
            get { return _Symbol; }
            set { _Symbol = value; }
        }
        
        public string CompanyName
        {
            get { return _CompanyName; }
            set { _CompanyName = value; }
        }

        public static Stock GetBySymbol(string symbol)
        {
            var query = from Stock s in Db.Get where s.Symbol == symbol select s;
            foreach (var stock in query)
            {
                return stock;
            }
            return null;
        }

        public static IEnumerable<Stock> GetAll()
        {
            return from Stock s in Db.Get select s;
        }

        public IEnumerable GetQuotationByDateInterval(DateTime initDate, DateTime endDate)
        {
            return
                from Quotation q in Db.Get
                where (q.Stock == this) &&
                      (q.Date >= initDate) &&
                      (q.Date <= endDate)
                orderby q.Date
                select q;
        }
    }
}
